package com.lqian.stream.reduce;

import java.util.Arrays;
import java.util.List;

public class ShopCarTest {
    public static void main(String[] args) {
        List<ShopCar> shopCars = Arrays.asList(new ShopCar(1, "手机1", 1d, 1),
                new ShopCar(2, "手机2", 2d, 2),
                new ShopCar(3, "手机3", 3d, 3));

        double sum1 = shopCars.stream()
                .map(shopCar -> shopCar.getPrice() * shopCar.getNum())
                .reduce(0d, (a, b) -> a + b)
                .doubleValue();
        System.out.println("总金额为："+sum1);
        System.out.println("-----------");
        double sum2 = shopCars.stream().mapToDouble(shopCar -> shopCar.getPrice() * shopCar.getNum()).sum();
        System.out.println("总金额为："+sum2);

        double priceAVG = shopCars.stream().mapToDouble(shopCar -> shopCar.getPrice()).average().getAsDouble();
        double priceMax = shopCars.stream().mapToDouble(shopCar -> shopCar.getPrice()).max().getAsDouble();
        double priceMin = shopCars.stream().mapToDouble(shopCar -> shopCar.getPrice()).min().getAsDouble();
        System.out.println(priceAVG);
        System.out.println(priceMax);
        System.out.println(priceMin);


    }

}
